package algorithms.leecode;

import java.util.ArrayList;
import java.util.List;

public class Au58 {
    public static void main(String[] args) {
        System.err.println(lengthOfLastWord("Hello World"));
    }
    public static int lengthOfLastWord(String s) {

        char[] array = s.toCharArray();
        List<Character> word = new ArrayList<>();
        boolean blank = false;
        for(int i = 0;i < array.length; i ++) {
            if(array[i] == ' ') {
                blank = true;
                continue;
            }
            if(blank && array[i] != ' ') {
                blank = false;
                word.clear();
                word.add(array[i]);
            } else {
                word.add(array[i]);
            }
        }
        return word.size();


    }
}
